﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Web.Security;
using System.Web.Profile;

using Gift.Model;
using Gift.Model.ENUM;
using Gift.DAL;
using System.Data;

namespace WebSite.admin
{
    public partial class login : System.Web.UI.Page
    {

        readonly adminlogin theAdminLogin = new adminlogin();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                string sSource = fun.geturl("");
                //if (((sSource != "127.0.0.1") && (fun.Left(sSource, 7) != "192.168")) && (sSource != "localhost"))
                //{
                    //if ((re.ReadCookie("code") != null) && (re.ReadCookie("code") != ""))
                    //{
                    //    string regname = fun.ReadValue("Sitezcn");
                    //    string regcode = fun.ReadValue("Sitezcv");
                    //    if (fun.weburl("", sSource, regname, regcode).ToString() != re.ReadCookie("code").ToString())
                    //    {
                    //        base.Response.Write("<script language=javascript src=website.aspx></script>");
                    //    }
                    //}
                    //else
                    //{
                    //    base.Response.Write("<script language=javascript src=website.aspx></script>");
                    //}
                //}
            }
        }

 

        protected void Button1_Click(object sender, ImageClickEventArgs e)
        {
            this.Session["Adminlogin"] = null;
            Session["memberid"] = null;
            Session["username"] = null;
            Session["rankid"] = null;
            Session["CompanyId"] = null;
            //if (base.Request.Cookies["CheckCode"] == null)
            //{
            //    base.Response.Write("<script language=javascript>alert('您的浏览器设置已被禁用Cookies,您必须设置浏览器允许使用Cookies选项后才能使用本系统。')</script>");
            //}
            if (Session["checkCode"] == null ||  string.Compare(Session["checkCode"].ToString(), this.txtCheckCode.Text.ToUpper(), true) != 0)
            {
                base.Response.Write("<script language=javascript>alert('验证码错误，请重新输入！');window.location.href='login.aspx';</script>");
            }
            else
            {
                string usn = re.replace(this.txtName.Text);
                string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(re.replace(this.txtPwd.Text), "MD5");
                WebSite.login.lo(usn, pwd);
                this.Session["Adminlogin"] = usn;
                try
                {
                    this.Session["inphoneNumber"] = theAdminLogin.GetInphoneNumberByName(usn);
                }
                catch { }
                this.Session.Timeout = 60;
            }
        }

    }
}